//设置
import React, { Component } from 'react'
import {
    ScrollView,
} from 'react-native';


import Resumetop from './every/resumetop';
import Resumebasic from './every/resumebasic';
import Resumevocation from './every/resumevocation.js';
import Resumeexperience from './every/resumeexperience';
import Resumeeducation from './every/resumeeducation';
import Resumeproject from './every/resumeproject';
import Resumeappraise from './every/resumeappraise';
import Resumeattach from './every/resumeattach';


import {
    EditResumeAction,
    UpdateResumeAction,
    updateJobExpAction,
    InsertJobExpAction,
    InsertEduAction,
    UpdateEduAction,
    InsertProAction,
    UpdateEducationAction,
} from '../../../actions/systemAction';      //加载action
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';

class Resume extends Component {
    // 初始化模拟数据
    constructor(props) {            //构造器只执行一次
        super(props);
    };

    //加载后渲染页面
    componentDidMount() {
        this.props.actions.EditResumeAction(); //初始化查询
    }

    render() {
        const { resume } = this.props.xz_resume.data;
        return (
            <ScrollView style={{ flex: 1, backgroundColor: "#f6f6f6" }}>
                <Resumetop
                    resume={resume}
                    actions={this.props.actions}
                    fields={resume.fields}
                    navigation={this.props.navigation} />
                <Resumebasic resume={resume} />
                <Resumevocation resume={resume} actions={this.props.actions} fields={resume.fields} navigation={this.props.navigation} />
                <Resumeexperience resume={resume} jobExps={resume.jobExps} actions={this.props.actions} navigation={this.props.navigation} />
                <Resumeeducation resume={resume} xzResumeEducations={resume.xzResumeEducations} actions={this.props.actions} navigation={this.props.navigation} />
                <Resumeproject resume={resume} xzProjectExps={resume.xzProjectExps} actions={this.props.actions} navigation={this.props.navigation} />
                <Resumeappraise resume={resume} actions={this.props.actions} navigation={this.props.navigation} />
                <Resumeattach resume={resume} actions={this.props.actions} navigation={this.props.navigation} />
                {/* <Resumeskill resume={resume} xzResumeSkills={resume.xzResumeSkills} navigation={this.props.navigation} /> */}
            </ScrollView>

        )
    }
}

//组合action
var actions = {
    EditResumeAction,
    UpdateResumeAction,
    updateJobExpAction,
    InsertJobExpAction,
    InsertEduAction,
    UpdateEduAction,
    InsertProAction,
    UpdateEducationAction
}

//连接state到props
const mapStateToProps = state => {
    return {
        xz_resume: state.EditResumeReducer
    }
}

//连接action
const mapDispatchToProps = (dispatch) => {
    return {
        actions: bindActionCreators(actions, dispatch)
    }
}

//导出组合好的组件(组合后状态改变重新渲染组合组件的页面)
export default connect(
    mapStateToProps, mapDispatchToProps
)(Resume);